home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / GR / GR_SPEC.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  17KB  |  512 lines

  1. /****************************************************************
  2.  
  3.     gr_spec.c    Specification of Graphics Interface 
  4.             for Space Flight Simulator
  5.  
  6.             Copyright (c) 1991, Ted A. Campbell
  7.  
  8.             Bywater Software
  9.             P. O. Box 4023 
  10.             Duke Station 
  11.             Durham, NC  27706
  12.  
  13.             email: tcamp@hercules.acpub.duke.edu
  14.  
  15.     Copyright and Permissions Information:
  16.  
  17.     All U.S. and international copyrights are claimed by the
  18.     author. The author grants permission to use this code
  19.     and software based on it under the following conditions:
  20.     (a) in general, the code and software based upon it may be 
  21.     used by individuals and by non-profit organizations; (b) it
  22.     may also be utilized by governmental agencies in any country,
  23.     with the exception of military agencies; (c) the code and/or
  24.     software based upon it may not be sold for a profit without
  25.     an explicit and specific permission from the author, except
  26.     that a minimal fee may be charged for media on which it is
  27.     copied, and for copying and handling; (d) the code must be 
  28.     distributed in the form in which it has been released by the
  29.     author; and (e) the code and software based upon it may not 
  30.     be used for illegal activities. 
  31.  
  32.     This file specifies the interface for graphics and mouse 
  33.     handling utilized in the Space Flight Simulator.  This file
  34.     may be utilized as the basis for implementations of gr and 
  35.     thus of sfs on varied computers.  If you can implement the
  36.     functions specified in this file, sfs should be implemented.
  37.  
  38.     COORDINATE SYSTEM. The gr interface presupposes throughout
  39.     a Cartesian coordinate system in which pixels on the vertical
  40.     axis (the y axis) are numbered beginning with 0 from the
  41.     bottom up, and pixels on the horizontal axis (the x axis)
  42.     are numbered beginning with 0 from the ;eft to the right.
  43.     The numbering of the y axis may seem counterintuitive,
  44.     since in many systems pixels are numbered vertically from
  45.     the top to the bottom.
  46.  
  47. ****************************************************************/
  48.  
  49. #include "stdio.h"
  50. #include "gr.h"
  51.  
  52. int     gr_colors;      /* number of colors available */
  53. int     gr_pxsize;      /* relative size of pixel, horizontal */
  54. int     gr_pysize;      /* relative size of pixel, vertical */
  55. int     gr_ismouse;     /* boolean -- does mouse exist? */
  56. int     gr_clipping;    /* boolean -- is clipping implemented? */
  57. int     gr_blitting;    /* boolean -- is blitting implemented? */
  58. int     gr_saving;      /* boolean -- is screen saving implemented? */
  59. int     gr_screens;     /* number of screens, 1 = visible screen
  60.                (GR_PRIMARY) only, 2 = visible and
  61.                hidden screen (GR_PRIMARY and GR_HIDDEN)
  62.                are available */
  63.  
  64. /****************************************************************
  65.  
  66.    gr_init()
  67.  
  68.    This function should initialize the entire graphics and mouse
  69.    subsystem. The argument "grwindow" is a pointer to a gr_window
  70.    structure which should be filled in by the function. The
  71.    argument "font_path" is a pointer to a character string
  72.    giving the name of a path where the function should look
  73.    for font and other data files. The function should return
  74.    BW_ERROR upon any error and TRUE upon a successful setting
  75.    of the graphics subsystem.
  76.  
  77. ****************************************************************/
  78.  
  79. gr_init( grwindow, font_path )
  80.    struct gr_window *grwindow;
  81.    char * font_path;
  82.    {
  83.    }
  84.  
  85. /****************************************************************
  86.  
  87.    gr_deinit()
  88.  
  89.    This function should deinitialize the entire graphics subsystem.
  90.  
  91. ****************************************************************/
  92.  
  93. gr_deinit()
  94.    {
  95.    }
  96.  
  97. /****************************************************************
  98.  
  99.    gr_cls()
  100.  
  101.    This function should clear the entire screen area.
  102.  
  103.    The argument "screen" is an integer denoted either the
  104.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  105.    to which graphics output can be written (defined as
  106.    GR_HIDDEN).
  107.  
  108. ****************************************************************/
  109.  
  110. gr_cls( screen )
  111.    int screen;
  112.    {
  113.    }
  114.  
  115.  
  116. /****************************************************************
  117.  
  118.    gr_pixel()
  119.  
  120.    This function turns on (or off, if the color is BLACK) a single
  121.    pixel on the display.
  122.  
  123.    The argument "screen" is an integer denoted either the
  124.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  125.    to which graphics output can be written (defined as
  126.    GR_HIDDEN).
  127.  
  128.    The arguments x and y specify a pixel location on the screen
  129.    in gr coordinates (see above on the coordinate system) where
  130.    the pixel is to be located, x on the horizontal axis and y
  131.    on the vertical axis.
  132.  
  133.    The argument "color" is an integer denoting a color defined
  134.    in the header "gr.h".
  135.  
  136. ****************************************************************/
  137.  
  138. gr_pixel( screen, x, y, color )
  139.    int screen;
  140.    int x, y;
  141.    int color;
  142.    {
  143.    }
  144.          
  145. /****************************************************************
  146.  
  147.    gr_line()
  148.  
  149.    This function draws a line on the designated screen from
  150.    point x1, y1 to point x2, y2 in a specified color and
  151.    with a specified style.
  152.  
  153.    The argument "screen" is an integer denoted either the
  154.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  155.    to which graphics output can be written (defined as
  156.    GR_HIDDEN).
  157.  
  158.    The arguments x1, y1, x2, and y2 specify two pixel locations
  159.    on the screen in gr coordinates (see above on the coordinate
  160.    system) denoting the source (x1, y1) and destination (x2, y2)
  161.    points for the line (x1 and x2 on the horizontal axis, and y1
  162.    and y2 on the vertical axis.
  163.  
  164.    The argument "color" is an integer denoting a color defined
  165.    in the header "gr.h".
  166.  
  167.    The argument "style" is an integer denoting a line style
  168.    defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- GRID
  169.    and HATCH denote dotted lines, and HOLLOW erases the area
  170.    of the line).
  171.  
  172. ****************************************************************/
  173.  
  174. gr_line( screen, x1, y1, x2, y2, color, style )
  175.    int screen;
  176.    int x1, y1, x2, y2;
  177.    int color, style;
  178.    {
  179.    }
  180.  
  181. /****************************************************************
  182.  
  183.    gr_text()
  184.  
  185.    This function addresses text to a specified location on the
  186.    screen in specified colors.
  187.  
  188.    The argument "screen" is an integer denoted either the
  189.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  190.    to which graphics output can be written (defined as
  191.    GR_HIDDEN).
  192.  
  193.    The arguments x and y specify a pixel location on the screen
  194.    in gr coordinates (see above on the coordinate system) where
  195.    the bottom left corner of the text is to be located, x on the
  196.    horizontal axis and y on the vertical axis.
  197.  
  198.    The argument "string" designates a pointer to a character
  199.    string to be written to the screen.
  200.  
  201.    The arguments "foreground" and "background" are integers
  202.    denoting text foreground and background colors as defined
  203.    in the header "gr.h".
  204.  
  205. ****************************************************************/
  206.  
  207. gr_text( screen, x, y, string, foreground, background )
  208.    int screen;
  209.    int x, y;
  210.    int foreground, background;
  211.    char *string;
  212.    {
  213.    }
  214.  
  215. /****************************************************************
  216.  
  217.    gr_strlen()
  218.  
  219.    This function returns the length in pixels on the horizontal
  220.    (x) axis of a specified character string.
  221.  
  222.    The argument "string" designates a pointer to a character
  223.    string whose horizontal size is to be calculated.
  224.  
  225. ****************************************************************/
  226.  
  227. unsigned int
  228. gr_strlen( string )
  229.    char *string;
  230.    {
  231.    }
  232.  
  233. /****************************************************************
  234.  
  235.    gr_rectangle()
  236.  
  237.    This function draws and possibly fills in (or blanks) a
  238.    rectangular area of the screen.
  239.  
  240.    The argument "screen" is an integer denoted either the
  241.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  242.    to which graphics output can be written (defined as
  243.    GR_HIDDEN).
  244.  
  245.    The arguments x1, y1, x2, and y2 specify two pixel locations
  246.    on the screen in gr coordinates (see above on the coordinate
  247.    system) denoting the bottom left corner (x1, y1) and top right
  248.    corner (x2, y2) of the rectangle (x1 and x2 on the horizontal
  249.    axis, and y1 and y2 on the vertical axis).
  250.  
  251.    The argument "color" is an integer denoting a color defined
  252.    in the header "gr.h".
  253.  
  254.    The argument "style" is an integer denoting a fill style
  255.    defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
  256.    means that only a perimeter is drawn; SOLID means that the
  257.    area is completely filled with the color, and GRID and HATCH
  258.    represent varying degrees of partial fill, with GRID the finer
  259.    and HATCH the rougher).
  260.  
  261. ****************************************************************/
  262.  
  263. gr_rectangle( screen, x1, y1, x2, y2, color, style )
  264.    int screen;
  265.    int x1, y1, x2, y2;
  266.    int color, style;
  267.    {
  268.    }
  269.  
  270. /****************************************************************
  271.  
  272.    gr_circle()
  273.  
  274.    This function draws and possibly fills in (or blanks) a
  275.    circular area of the screen.
  276.  
  277.    The argument "screen" is an integer denoted either the
  278.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  279.    to which graphics output can be written (defined as
  280.    GR_HIDDEN).
  281.  
  282.    The arguments x and y specify a pixel location on the screen
  283.    in gr coordinates (see above on the coordinate system) where
  284.    the center of the circle is to be located, x on the horizontal
  285.    axis and y on the vertical axis.
  286.  
  287.    The argument "radius" is an integer denoting the radius of the
  288.    circle on the y (vertical) axis. Implementers should note that
  289.    the x (horizontal) axis will have to be scaled.
  290.  
  291.    The argument "color" is an integer denoting a color defined
  292.    in the header "gr.h".
  293.  
  294.    The argument "style" is an integer denoting a fill style
  295.    defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
  296.    means that only a perimeter is drawn; SOLID means that the
  297.    area is completely filled with the color, and GRID and HATCH
  298.    represent varying degrees of partial fill, with GRID the finer
  299.    and HATCH the rougher).
  300.  
  301. ****************************************************************/
  302.  
  303. gr_circle( screen, x, y, radius, color, style )
  304.    int screen;
  305.    int x, y, radius;
  306.    int color, style;
  307.    {
  308.    }
  309.  
  310. /****************************************************************
  311.  
  312.    gr_ellipse()
  313.  
  314.    This function is NOT CURRENTLY USED in any Bywater applications
  315.    so it's here basically for future development.
  316.  
  317.    This function draws and possibly fills in (or blanks) an
  318.    elliptical area of the screen.
  319.  
  320.    The argument "screen" is an integer denoted either the
  321.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  322.    to which graphics output can be written (defined as
  323.    GR_HIDDEN).
  324.  
  325.    The arguments x and y specify a pixel location on the screen
  326.    in gr coordinates (see above on the coordinate system) where
  327.    the center of the ellipse is to be located, x on the horizontal
  328.    axis and y on the vertical axis.
  329.  
  330.    The arguments "x_radius" and "y_radius" specify the horizontal
  331.    and vertical sizes, respectively, of the bounding rectangle
  332.    of the ellipse.
  333.  
  334.    The argument "color" is an integer denoting a color defined
  335.    in the header "gr.h".
  336.  
  337.    The argument "style" is an integer denoting a fill style
  338.    defined in "gr.h" (HOLLOW, SOLID, GRID, or HATCH -- HOLLOW
  339.    means that only a perimeter is drawn; SOLID means that the
  340.    area is completely filled with the color, and GRID and HATCH
  341.    represent varying degrees of partial fill, with GRID the finer
  342.    and HATCH the rougher).
  343.  
  344. ****************************************************************/
  345.  
  346. gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
  347.    int screen;
  348.    int x, y, x_radius, y_radius;
  349.    int mode, color, style;
  350.    {
  351.    }
  352.          
  353. /****************************************************************
  354.  
  355.    gr_clip()
  356.  
  357.    If clipping is implemented (gr_clipping == TRUE), this
  358.    function turns on or off clipping for a specified area
  359.    of the screen.
  360.  
  361.    The argument "screen" is an integer denoted either the
  362.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  363.    to which graphics output can be written (defined as
  364.    GR_HIDDEN).
  365.  
  366.    The argument "mode" is a boolean integer which tells whether
  367.    clipping is to be turned on (TRUE) or off (FALSE).
  368.  
  369.    The arguments x1, y1, x2, and y2 specify two pixel locations
  370.    on the screen in gr coordinates (see above on the coordinate
  371.    system) denoting the bottom left corner (x1, y1) and top right
  372.    corner (x2, y2) of the clipping rectangle (x1 and x2 on the
  373.    horizontal axis, and y1 and y2 on the vertical axis).
  374.  
  375. ****************************************************************/
  376.  
  377. gr_clip( screen, mode, x1, y1, x2, y2 )
  378.    int screen;
  379.    int mode;
  380.    int x1, y1, x2, y2;
  381.    {
  382.    }
  383.  
  384. /****************************************************************
  385.  
  386.    gr_font()
  387.  
  388.    This function sets a font for future calls to gr_text().
  389.  
  390.    The argument "screen" is an integer denoted either the
  391.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  392.    to which graphics output can be written (defined as
  393.    GR_HIDDEN).
  394.  
  395.    The argument "type" is an integer value (not currently
  396.    implemented in applications by Bywater Software) which would
  397.    denote a font type (these are defined in "gr.h" as F_DEFAULT,
  398.    F_ROMAN, F_ITALIC, and F_GOTHIC). Don't worry about it.
  399.  
  400.    The argument "rq_height" is an integer value denoting the
  401.    requested height of the new font in pixels. The function should
  402.    set the closest available height and then denote the size of
  403.    the new font in the fysize variable in the gr_display structure.
  404.  
  405. ****************************************************************/
  406.  
  407. gr_font( screen, type, rq_height )
  408.    int screen;
  409.    int type, rq_height;
  410.    {
  411.    }
  412.  
  413. /****************************************************************
  414.  
  415.    gr_blit()
  416.  
  417.    This function "blits" (copies) a rectangular area of the screen
  418.    from GR_PRIMARY to GR_HIDDEN or vice versa (if blitting is
  419.    implemented, i.e., gr_blitting == TRUE).
  420.  
  421.    The arguments "src" and "dst" are integers denoting either the
  422.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  423.    to which graphics output can be written (defined as
  424.    GR_HIDDEN). Obviously, one should be set to GR_PRIMARY and
  425.    one to GR_HIDDEN. "src" denotes the source of the blit, and
  426.    "dst" the destination.
  427.  
  428.    The arguments x1, y1, x2, and y2 specify two pixel locations
  429.    on the screen in gr coordinates (see above on the coordinate
  430.    system) denoting the bottom left corner (x1, y1) and top right
  431.    corner (x2, y2) of the area to be blitted (x1 and x2 on the
  432.    horizontal axis, and y1 and y2 on the vertical axis).
  433.  
  434. ****************************************************************/
  435.  
  436. gr_blit( src, dst, x1, y1, x2, y2 )
  437.    int src, dst;
  438.    int x1, y1, x2, y2;
  439.    {
  440.    }
  441.  
  442. /****************************************************************
  443.  
  444.    gr_imsave()
  445.  
  446.    This function either saves a rectangluar area of the screen to
  447.    a memory buffer (mode == TRUE), or restores a rectangular screen
  448.    area from the buffer (mode == FALSE). It should free existing memory
  449.    when mode == FALSE (thus, the area cannot be restored more than once).
  450.  
  451.    The argument "screen" is an integer denoted either the
  452.    visible screen (defined as GR_PRIMARY) or a hidden buffer
  453.    to which graphics output can be written (defined as
  454.    GR_HIDDEN).
  455.  
  456.    The arguments x1, y1, x2, and y2 specify two pixel locations
  457.    on the screen in gr coordinates (see above on the coordinate
  458.    system) denoting the bottom left corner (x1, y1) and top right
  459.    corner (x2, y2) of the rectangular area to be saved (x1 and x2
  460.    on the horizontal axis, and y1 and y2 on the vertical axis).
  461.  
  462.    The argument "image" is an integer denoting the specific
  463.    image that has been (or is to be) stored.
  464.  
  465. ****************************************************************/
  466.  
  467. gr_imsave( screen, mode, x1, y1, x2, y2, image )
  468.    int screen; 
  469.    int mode, x1, y1, x2, y2;
  470.    int *image;
  471.    {
  472.    }
  473.  
  474. /****************************************************************
  475.  
  476.     gr_imfree()
  477.  
  478. ****************************************************************/
  479.  
  480. gr_imfree( image )
  481.    int image;
  482.    {
  483.    }
  484.  
  485. /****************************************************************
  486.  
  487.    gr_mouse()
  488.  
  489.    This function either tells if a mouse button has been pushed
  490.    (mode == SAMPLE or STATUS) or waits for a button to be pushed
  491.    (mode == WAIT).
  492.  
  493.    The arguments x and y are integer pointers to be filled with a
  494.    screen location in gr coordinates (see above on the coordinate
  495.    system) where the mouse is currently located, x on the horizontal
  496.    axis and y on the vertical axis.
  497.  
  498.    The argument "buttons" is an integer pointer which some great
  499.    day will be used to specify which of the mouse buttons has been
  500.    pushed but it hasn't been used yet in any Bywater applications
  501.    so don't worry about it.
  502.  
  503. ****************************************************************/
  504.  
  505. gr_mouse( mode, x, y, buttons )
  506.    int mode;
  507.    int *x, *y;
  508.    int *buttons;
  509.    {
  510.    }
  511.  
  512.